package com.service_api.service;

import com.service_api.model.EduExpSalary;
import com.service_api.repository.EduExpSalaryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class EduExpSalaryService {
    @Autowired
    EduExpSalaryRepository eduExpSalaryRepository;

    public List<Object> getEduExpSalaryList(String city) {
        List<EduExpSalary> allByCity = eduExpSalaryRepository.findAllByCity(city);
        ArrayList<Object> resultList = new ArrayList<>();
        ArrayList<Integer[]> dataList = new ArrayList<>();
        ArrayList<String> xList = new ArrayList<>();
        ArrayList<String> yList = new ArrayList<>();
        for (EduExpSalary temp : allByCity) {
            String yValue = temp.getId().getExperience();
            int yIndex = yList.indexOf(yValue);
            if (yIndex < 0) {
                yList.add(yValue);
                yIndex = yList.indexOf(yValue);
            }
            String xValue = temp.getId().getQualifications();
            int xIndex = xList.indexOf(xValue);
            if (xIndex < 0) {
                xList.add(xValue);
                xIndex = xList.indexOf(xValue);
            }
            dataList.add(new Integer[]{xIndex, yIndex, temp.getValue()});
        }
        resultList.add(xList);
        resultList.add(yList);
        resultList.add(dataList);

        return resultList;
    }
}
